<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('表格传值给父页面')" />
</head>
<body class="gray-bg">
<input type="hidden" id="rowIds">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var prefix = ctx + "lh/software";
    var machineTypeDatas = [[${@dict.getType('lh_machine_type')}]];
    var releaseAreaDatas = [[${@dict.getType('lh_machine_area')}]];
    var statusDatas = [[${@dict.getType('lh_machine_open')}]];
    var isAcceptUpdateDatas = [[${@dict.getType('lh_machine_accept')}]];
    var type = [[${type}]];
    var abledUpdateSoftware = [[${abledUpdateSoftware}]];
    var disabledSoftware = [[${disabledSoftware}]];
    var checkedValues = [[${checkedValues}]];

    // var abledUpdateSoftware = '';
    // var disabledSoftware = '';
    // var checkedValues = '';

    $(function() {
            var options = {
            url: prefix + "/machineList?type=" + type + "&abledUpdateSoftware=" + abledUpdateSoftware + "&disabledSoftware=" + disabledSoftware,
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            columns: [{
                    checkbox: true,
                    formatter: function (value, row) {
                        var arr = checkedValues.split(',');
                        var result = arr.some(ele => ele === row.sn)
                        if(result){
                            return {  checked: true };
                        }else {
                            return {  checked: false };
                        }
                    }
                },
                {
                    field: 'id',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'projectName',
                    title: '项目名称'
                },
                {
                    field: 'machineNo',
                    title: '设备型号'
                },
                {
                    field: 'machineType',
                    title: '设备类型',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(machineTypeDatas, value);
                    }
                },
                {
                    field: 'sn',
                    title: '设备SN'
                },
                {
                    field: 'hardwareVersion',
                    title: '硬件版本'
                },
                {
                    field: 'initialSoftwareVersion',
                    title: '初始软件版本'
                },
                {
                    field: 'status',
                    title: '软件/设备状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field: 'releaseDate',
                    title: '出厂时间'
                },
                {
                    field: 'releaseArea',
                    title: '设备所在区域',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(releaseAreaDatas, value);
                    }
                },
                {
                    field: 'isAcceptUpdate',
                    title: '是否允许更新',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(isAcceptUpdateDatas, value);
                    }
                }]
        };
        $.table.init(options);
    });

    /* 添加用户-选择用户-提交(子页面调用父页面形式) */
    function submitHandler(index, layero) {
        var rows = $.table.selectFirstColumns();
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        $.modal.close();
        // 父页面的方法
        activeWindow().ddjsa(rows);
        // 父页面的变量
        // activeWindow().;
    }

    /* 添加用户-选择用户-提交(回调形式-父页面调用子页面) */
    function getSelections() {
        var rows = $("#bootstrap-table").bootstrapTable('getSelections');
        return rows;
    }

    $("#bootstrap-table").on("check.bs.table check-all.bs.table uncheck.bs.table uncheck-all.bs.table", function (e, rowsAfter, rowsBefore) {
        var rows = $.common.equals("uncheck-all", e.type) ? rowsBefore : rowsAfter;
        console.log()
        var rowIds = $.table.affectedRowIds(rows);
        $("#rowIds").val(rowIds);
    });

    // $('#bootstrap-table').on('load-success.bs.table',function(data){
    //     if(checkedValues != null && checkedValues != '') {
    //         console.log(checkedSN);
    //         $('#bootstrap-table').bootstrapTable("checkBy",{field: 'sn', checkedSN});
    //     }
    // });
</script>
</body>
</html>